import request from './request'
import {AxiosResponse } from "axios"
const defaultHandle = (api: Promise<AxiosResponse>) => {
    return api.then((res:AxiosResponse) => {
        // console.log("res:",res)
        if (
          res?.data?.code === 0 ||res?.data?.code === 1
        ){
          return Promise.resolve(res?.data)
        } 
      })
      .catch((err:any) => {
        console.log('err: ', err)
      })
  }
  
//登录
export const Login=(data:Object)=>defaultHandle(  
    request.post('/login', {...data},{
    headers: {
        'Content-Type': 'application/json',
    }
  }))
  //注册
export const Register=(data:Object)=>defaultHandle(  
    request.post('/register', {...data},{
    headers: {
        'Content-Type': 'application/json',
    }
  }))
//获取文章列表
export const GetArticleList=(data:Object)=>defaultHandle(
  request.get('/getArticleList',   
  {
    params:data,
  })
)
//新增文章
export const AddArticle=(data:Object)=>defaultHandle(
  request.post('/addArticle', {...data},{
    headers: {
        'Content-Type': 'application/json',
    }
}))
//给文章点赞
export const UpdateArticle=(data:Object)=>defaultHandle(
  request.post('/updateArticle',{...data},{
    headers: {
      'Content-Type': 'application/json',
    }
  })
)
//获取标签列表
export const GetTagList=(data:Object)=>defaultHandle(
  request.get('/getTagList',   
  {
    params:data,
  })
)
//获取项目列表
export const GetProjectList=(data:Object)=>defaultHandle(
  request.get('/getProjectList',   
  {
    params:data,
  })
)
//获取文章详情
export const GetArtiDetail=(data:Object)=>defaultHandle(
  request.post('/getArtiDetail', {...data},{
    headers: {
        'Content-Type': 'application/json',
    }
}))
//一级评论
export const AddComment=(data:Object)=>defaultHandle(
  request.post('/addComment',{...data},{
    headers: {
      'Content-Type': 'application/json',
    }
  })
)
//添加多级评论
export const AddThridCom=(data:Object)=>defaultHandle(
  request.post('/addThirdCom',{...data},{
    headers: {
      'Content-Type': 'application/json',
    }
  })
)
//获取多级评论
export const GetOtherCom=(data:Object)=>defaultHandle(
  request.get('/getOtherCom',   
  {
    params:data,
  })
)
//给文章点赞
export const LikeArticle=(data:Object)=>defaultHandle(
  request.post('/likeArticle',{...data},{
    headers: {
      'Content-Type': 'application/json',
    }
  })
)